package Offer2019;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+"\t上完自习，离开教室");
                countDownLatch.countDown();//减一
            },String.valueOf(i)).start();
        }


        countDownLatch.await();//使当前线程等待直到锁存器计数到零为止
        System.out.println(Thread.currentThread().getName()+"\t班长关门走人");
    }

    //public static void main(String[] args) throws InterruptedException {
    //    CountDownLatch countDownLatch = new CountDownLatch(6);
    //
    //    for (int i = 1; i <= 6; i++) {
    //        new Thread(() -> {
    //            System.out.println(Thread.currentThread().getName()+"\t国，被灭");
    //            countDownLatch.countDown();
    //        },CountryEnum.forEach_CountryEnum(i).getRetMessage()).start();
    //    }
    //
    //
    //    countDownLatch.await();
    //    System.out.println(Thread.currentThread().getName()+"\t大秦帝国，一统华夏");
    //}
}
